#ifndef MYSERIALPORT_H
#define MYSERIALPORT_H

#include <QMutex>
#include <QObject>
#include <QSemaphore>
#include <QSerialPort>
#include <QThread>
#include <QTimer>
#include <QSerialPort>

#include <QDebug>
#include "global.h"
class MySerialPortSettings
{
public:
    MySerialPortSettings();
    MySerialPortSettings(const MySerialPortSettings& setting);
    MySerialPortSettings & operator=(const MySerialPortSettings &setting);

    QString portName;
    int baudRate;
    QSerialPort::Parity parity;
    QSerialPort::DataBits dataBits;
    QSerialPort::StopBits stopBits;
    QSerialPort::FlowControl flowControl= QSerialPort::NoFlowControl;
};


class MySerialPort:public QObject
{
    Q_OBJECT
public:
    enum MARK{
        OpenSuccess,
        OpenFail,
        ReceiveData,
        Res_Success=0,

        RES_NULLDATA=1,
        RES_TIMEOUT=2,
        RES_PROERROR=3
    };

    explicit MySerialPort(const MySerialPortSettings & setting,RES& res,QObject *parent=nullptr);

    ~MySerialPort();

private:
    int init(const MySerialPortSettings & setting);
public slots:
    void slSendData(QByteArray data);
private slots:
    //void slAcquireLYPVersion();
    //void slGetLYPVersion();
    void slReceiveData();
    //void slReceiveTimeOut();
protected:
    //void eventAcquire(){_eventPtr->acquire();}
    //void eventRelease(){_eventPtr->release();}
signals:
    //void sgSerialPortMsg(int mark,const QByteArray &data="",int dk=0);
    void sgSPReceiveData(const QByteArray data);
private:
    QThread* _thread;
    QSerialPort * _sp;

};

#endif // MYSERIALPORT_H
